package com.ocom.company.controller;

import com.github.pagehelper.PageInfo;
import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.entity.noticeBoard.EntityNoticeBoardInfo;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.ComIdRequest;
import com.ocom.common.request.IdRequest;
import com.ocom.common.request.company.GetNoticeBoardByComRequest;
import com.ocom.common.request.company.GetNoticeBoardListRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.service.NoticeBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 2024-05-29
 */
@RestController
public class NoticeBoardController {
    @Autowired
    private NoticeBoardService noticeBoardService;

    @PostMapping(CompanyServiceUrl.URL_getNoticeBoardList)
    public Result getNoticeBoardList(@RequestBody GetNoticeBoardListRequest getNoticeBoardListRequest) {
        PageInfo<EntityNoticeBoardInfo> list = noticeBoardService.getNoticeBoardList(getNoticeBoardListRequest);
        if(list==null){
            return ResultUtil.error(ResultEnum.Err_1001);
        }
        return ResultUtil.success(list);
    }

    @PostMapping(CompanyServiceUrl.URL_addNoticeBoard)
    public Result addNoticeBoard(@RequestBody EntityNoticeBoardInfo entityNoticeBoardInfo) {
        return noticeBoardService.addNoticeBoard(entityNoticeBoardInfo);
    }

    @PostMapping(CompanyServiceUrl.URL_modifyNoticeBoard)
    public Result updateNoticeBoard(@RequestBody EntityNoticeBoardInfo entityNoticeBoardInfo) {
        return noticeBoardService.updateNoticeBoard(entityNoticeBoardInfo);
    }

    @PostMapping(CompanyServiceUrl.URL_deleteNoticeBoard)
    public Result deleteNoticeBoard(@RequestBody IdRequest idRequest) {
        return noticeBoardService.deleteNoticeBoard((long) idRequest.getId());
    }

    @PostMapping(CompanyServiceUrl.URL_homeNoticeBoard)
    public Result homeNoticeOnShow(@RequestBody ComIdRequest comIdRequest){
        return noticeBoardService.homeNoticeOnShow(comIdRequest.getComId());
    }

    @PostMapping(CompanyServiceUrl.URL_getNoticeBoardByCom)
    public Result getNoticeBoardByCom(@RequestBody GetNoticeBoardByComRequest getNoticeBoardByComRequest){
        return ResultUtil.success(this.noticeBoardService.getNoticeBoardByCom(getNoticeBoardByComRequest.getComId(), getNoticeBoardByComRequest.getRole()));
    }
}
